package com.kedacom.ctsp.authority.controller;

import com.kedacom.ctsp.authority.constant.AccessLoggerConstant;
import com.kedacom.ctsp.authority.entity.DataDictCategory;
import com.kedacom.ctsp.authority.service.DataDictCategoryService;
import com.kedacom.ctsp.authority.vo.DataDictCategoryVO;
import com.kedacom.ctsp.lang.mapper.BeanMapper;
import com.kedacom.ctsp.logging.AccessLogger;
import com.kedacom.ctsp.web.controller.AbstractCrudController2;
import com.kedacom.ctsp.web.controller.message.ResponseMessage;
import com.kedacom.ctsp.web.controller.util.QueryParamUtil;
import com.kedacom.ctsp.web.entity.page.PagerResult;
import com.kedacom.ctsp.web.entity.param.QueryParamEntity;
import io.swagger.annotations.Api;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.Collection;
import java.util.List;

@ResponseBody
@Api(tags = "dataDictCategory", description = "字典分类表")
@AccessLogger(AccessLoggerConstant.Module.DATA_DICT_CATEGORY)
@RequestMapping("${ctsp.web.mappings.authority.dataDictCategory:dataDictCategory}")
public class DataDictCategoryController extends AbstractCrudController2<DataDictCategory, String, DataDictCategoryVO, DataDictCategoryService> {

    @Override
    public ResponseMessage<String> updateByPrimaryKey(String id, DataDictCategoryVO data) {
        return super.patchByPrimaryKey(id, data);
    }

    @GetMapping("/allCategory")
    public ResponseMessage<Collection<DataDictCategoryVO>> getAll() {

        List<DataDictCategory> dataDictCategoryList = getService().getAll();

        Collection<DataDictCategoryVO> abilityGroupVOs = BeanMapper.deepMap(dataDictCategoryList, DataDictCategoryVO.class);
        return ResponseMessage.ok(abilityGroupVOs);
    }

    /**
     * 字典分类列表
     *
     * @param queryParam
     * @param request
     * @return
     */
    @GetMapping("/category-list")
    public ResponseMessage<Collection<DataDictCategory>> categoryList(QueryParamEntity queryParam, HttpServletRequest request) {
        QueryParamUtil.paddingTerms(queryParam, request);
        queryParam.setPaging(false);
        PagerResult<DataDictCategory> dataDictCategoryPagerResult = getService().selectPager(queryParam);
        return ResponseMessage.ok(dataDictCategoryPagerResult.getData());
    }
}
